package com.lingyuan.warehouse.controller;

import com.alibaba.fastjson.JSON;
import com.lingyuan.common.core.domain.R;
import com.lingyuan.common.core.domain.vo.call.WareCall;
import com.lingyuan.common.core.domain.vo.wms.WmsWareSkuVO;
import com.lingyuan.common.core.web.controller.BaseController;
import com.lingyuan.common.core.web.page.TableDataInfo;
import com.lingyuan.warehouse.domain.WmsWareSkuPO;
import com.lingyuan.warehouse.service.WareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author：寇可往，我亦可往。
 * @Package：com.lingyuan.controller
 * @Project：lingyuan-shopping-mall
 * @name：WareController
 * @Date：2024/9/18 10:22
 */
@RestController
@RequestMapping("/wms")
@Slf4j
public class WareController extends BaseController {

    @Autowired
    private WareService wareService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 获取仓库预警列表
     *
     * @param skuName
     * @return
     */
    @GetMapping("/wareList")
    public TableDataInfo getWareSkuList(@RequestParam(value = "skuName",required = false) String skuName,
                                        @RequestParam(value = "userId",required = false) Integer userId)
    {
        log.info ( "ware list :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( skuName ) );
        this.startPage ();
        List<WmsWareSkuVO> wareSkuList = wareService.getWareSkuList(skuName, userId);
        log.info ( "ware list :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( wareSkuList ) );
        return getDataTable ( wareSkuList );
    }


    /**
     *添加仓库库存
     *
     * @param
     * @return
     */
    @PostMapping("/wareByIdAdd")
    public R wareByIdAdd(@RequestBody WmsWareSkuPO wmsWareSkuPO)
    {
        log.info ( "ware list :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( wmsWareSkuPO ) );
        wareService.wareByIdAdd(wmsWareSkuPO);
        log.info ( "ware list :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( null ) );
        return R.ok ();
    }


    /**
     * 获取仓库列表
     *
     * @param skuName
     * @return
     */
    @GetMapping("/beforehandList")
    public TableDataInfo beforehandList(@RequestParam(value = "skuName",required = false) String skuName,
                                        @RequestParam(value = "userId",required = false) Integer userId)
    {
        log.info ( "ware list :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( skuName ) );
        this.startPage ();
        List<WmsWareSkuVO> wareSkuList = wareService.fandAll ();
        log.info ( "ware list :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( wareSkuList ) );
        return getDataTable ( wareSkuList );
    }

    /**
     * 添加仓库
     * @param skuName
     * @return
     */
    @PostMapping("/wareAdd")
    public R<Object> wareAdd(@RequestBody WmsWareSkuPO skuName)
    {
        log.info ( "ware add :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( skuName ) );
          wareService.wareAdd(skuName);
        log.info ( "ware add :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( null ) );
        return R.ok ();
    }

    /**
     * 修改仓库预警
     * @param skuName
     * @return
     */
    @PostMapping("/wareUpdate")
    public R<Object> wareUpdate(@RequestBody WmsWareSkuPO skuName)
    {
        log.info ( "wareUpdate :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( skuName ) );
            wareService.updateById ( skuName );
        log.info ( "wareUpdate :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( null ) );
        return R.ok ();
    }

    /**
     * 删除仓库预警
     * @param id
     * @return
     */
    @GetMapping("/wareRemoveById")
    public R<Object> wareRemoveById(@RequestParam("id") Integer id)
    {
        log.info ( "wareRemoveById :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( id ) );
        wareService.removeById ( id );
        log.info ( "wareRemoveById :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( null ) );
        return R.ok ();
    }


    /**
     * 减库存
     */
    @PostMapping("/wareLock")
    public R<Object> wareLock(@RequestBody List<WareCall> wareSkuList)
    {
        log.info ( "wareLock :  方法：{}  路经：{}  入参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( wareSkuList ) );
        wareService.wareLock(wareSkuList);
        log.info ( "wareLock :  方法：{}  路经：{}  出参：{}", request.getMethod (),
                request.getRequestURI (), JSON.toJSONString ( null ) );
        return R.ok ();
    }




}
